<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>JSBridge 调试页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body { font-family: sans-serif; padding: 20px; background: #f8f8f8; }
        button { display: block; width: 100%; padding: 14px; margin: 10px 0; font-size: 16px; border: none; border-radius: 5px; background-color: #1976d2; color: white; }
        #log { background: #fff; padding: 10px; border: 1px solid #ccc; margin-top: 20px; min-height: 100px; white-space: pre-wrap; font-size: 14px; }
    </style>
</head>
<body>
<h2>JSBridge 接口调试页</h2>

<img id="preview" style="width: 100px;height:100px" />
<button onclick="callGoHome()">xGoHome</button>
<button onclick="callGoLogin()">xGoLogin</button>
<button onclick="callGoLoginCompany()">xGoLoginCompany</button>
<button onclick="callScan()">xScan</button>
<button onclick="callCamera()">xCamera</button>
<button onclick="callPreviewPicture()">xPreviewPicture</button>
<button onclick="callLocation()">xLocation</button>
<button onclick="callUploadImage()">xUploadImage</button>
<button onclick="call302()">x302</button>

<h3>返回结果：</h3>
<div id="log"></div>

<script type="text/javascript">
    function log(title, content) {
        const logEl = document.getElementById('log');
        const line = `[${new Date().toLocaleTimeString()}] ${title}:\n${content}\n\n`;
        logEl.innerText += line;
    }

    function callGoHome() {
        window.WebViewJavascriptBridge.callHandler('xGoHome', '');
        log('xGoHome', '已调用，无返回值');
    }

    function callGoLogin() {
        window.WebViewJavascriptBridge.callHandler('xGoLogin', '');
        log('xGoLogin', '已调用，无返回值');
    }

    function callGoLoginCompany() {
        window.WebViewJavascriptBridge.callHandler('xGoLoginCompany', '');
        log('xGoLoginCompany', '已调用，无返回值');

    }

    function callScan() {
        window.WebViewJavascriptBridge.callHandler('xScan', '', function(data) {
            try {
                const json = JSON.parse(data);
                if (json.code === 1) {
                    log('xScan', '✅ 成功: ' + json.result.content);
                } else {
                    log('xScan', '❌ 失败: ' + json.msg);
                }
            } catch (e) {
                log('xScan', '❌ JSON解析异常: ' + e);
            }
        });
    }

    function callCamera() {
        window.WebViewJavascriptBridge.callHandler('xCamera', '', function(data) {
            try {
                const json = JSON.parse(data);
                if (json.code === 1) {
                    document.getElementById('preview').src = json.result.path;
                    log('xCamera', '📸 成功: ' +  json.result.path);
                } else {
                    log('xCamera', '❌ 失败: ' + json.msg);
                }
            } catch (e) {
                log('xCamera', '❌ JSON解析异常: ' + e);
            }
        });
    }

    function callPreviewPicture() {
        const paths = [
        "https://fastly.picsum.photos/id/237/800/600.jpg?hmac=KK6IftaxyI6scjoxeWUHr2AWr-7RQuExLH9vY4hSR6w",
        "https://fastly.picsum.photos/id/237/800/600.jpg?hmac=KK6IftaxyI6scjoxeWUHr2AWr-7RQuExLH9vY4hSR6w"];
        window.WebViewJavascriptBridge.callHandler('xPreviewPicture', paths);
        log('xPreviewPicture', JSON.stringify(paths, null, 2));
    }

    function callLocation() {
        window.WebViewJavascriptBridge.callHandler('xLocation', '', function(data) {
            try {
                const json = JSON.parse(data);
                if (json.code === 1) {
                    log('xLocation', `📍 经度: ${json.result.lng}, 纬度: ${json.result.lat}`);
                } else {
                    log('xLocation', '❌ 失败: ' + json.msg);
                }
            } catch (e) {
                log('xLocation', '❌ JSON解析异常: ' + e);
            }
        });
    }

    function callUploadImage() {
        window.WebViewJavascriptBridge.callHandler('xUploadImage', '', function(data) {
            try {
                log('xUploadImage', '📸 成功: ' +  data);
            } catch (e) {
                log('xUploadImage', '❌ 解析异常: ' + e);
            }
        });
    }

    function call302() {
        window.location.href = "https://www.baidu.com";
    }
</script>
</body>
</html>
